layui.use(['laydate','form','table','layer','laytpl'], function(){
	var laydate = layui.laydate,form = layui.form,table = layui.table,layer = layui.layer,laytpl = layui.laytpl;
	/*开始时间*/
	laydate.render({
	  	elem: '#start' //指定元素
	});
	/*结束时间*/
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@维修员-员工信息*/
	repair_info = function(info)
	{
		html = '<thead>'+
				'	<tr>'+
				'		<th>员工编号</th>'+
				'		<th>姓名</th>'+
				'		<th>性别</th>'+
				'		<th>所属部门</th>'+
				'		<th>员工职位</th>'+
				'		<th>联系方式</th>'+
				'		<th>入职日期</th>'+
	    		'		<th>维修总订单</th>'+
				'		<th>维修总额（元）</th>'+
				'		<th>维修总成本（元）</th>'+
				'		<th>人工费总额（元）</th>'+
				'		<th>维修总提成（元）</th>'+
				'	</tr>'+
			  	'</thead>'+
			  	'<tbody>'+  	
				'	<tr>'+
				'		<td>'+info.admin_sn+'</td>'+
				'		<td>'+info.nkname+'</td>'+
				'		<td>'+info.sex_text+'</td>'+
				'		<td>'+info.shop_name+'</td>'+
				'		<td>'+info.g_title+'</td>'+
				'		<td>'+info.phone+'</td>'+
				'		<td>'+info.addtime+'</td>'+
				'		<td>'+info.count_repair.repair_num+'</td>'+
				'		<td>'+info.count_repair.repair_money+'</td>'+
				'		<td>'+info.count_repair.parts_money+'</td>'+
				'		<td>'+info.count_repair.people_money+'</td>'+
				'		<td>'+info.count_repair.royalty_money+'</td>'+
	            '	</tr>'+
				'</tbody>';
		$('#staff-list').html(html)
	}
	/*@维修员-接口请求*/
	repair_list = function(){
		$.get("/staff/staff/sale_list",{},function(data){
			console.log(data)
			if(data.code !== 1){
				layer.msg(data.msg, {icon: 5});
				return
			}
			repair_info(data.msg);
		})
	}


	repair_list()
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '#repair-table',
	    url: '/staff/repair/index', //数据接口
	    page: false, //开启分页
	    cols: [[ //表头
	    	{field: 'id', title: '序号'},
	    	{field: 'shopname', title: '维修门店'},
	    	{field: 'repair_sn', title: '维修编号'},
	    	{field: 'addtime', title: '订单时间'},
	    	{field: 'username', title: '客户姓名'},
	    	{field: 'phone', title: '联系方式'},
	    	{field: 'user_sn', title: '客户编号'},
	    	{field: 'goods_name', title: '设备名称'},
	    	{field: 'imei', title: 'IMEI'},
	    	{field: 'sn', title: 'S/N'},
	    	{field: 'repair_money', title: '维修金额'},
	    	{field: 'parts_money', title: '配件金额'},
	    	{field: 'people_money', title: '人工费金额'},
	    	{field: 'repair_t_money', title: '维修提成'},
	    	{field: 'admin_nkname', title: '工作人员'},
	    	{field: 'tech_nkname', title: '维修人员'},
	    	{title: '操作', width: '100', toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'维修详情\',\'/staff/repair/details/ids/{{d.repair_id}}\')">详情</a></div>'},
	    ]],
	    parseData: function(res){
	    	console.log(res)
	    	if(res.code === 0){
	    		var num = (res.page - 1) * res.row
	    		var all = res.data.count
	    		res.data = res.data.list
		    	for(var i = 0;i < res.data.length;++i){
		    		res.data[i].id = num + i + 1
		    	}
		    	/*@统计*/
				var getTpl_2 = repair_count.innerHTML;
				var count = document.getElementById('repair-count');
				laytpl(getTpl_2).render(all, function(html){
					count.innerHTML = html;
				});
	    	}
	    	console.log(all)
	    }
	});

	/*@查询*/
	form.on('submit(search)',function(data){

		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		/*重载表格数据*/
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
});